#include <stdio.h>

#define N 20

typedef struct node_s {
	struct node_s *left, *right; 
	char val; 
}node_t; 

char preorder[N], inorder[N], postorder[N]; 

node_t node[N]; 
int nr_node; 

node_t *alloc_node(char v)
{
	node_t *n=&node[nr_node++]; 
	n->left = NULL; 
	n->right = NULL; 
	n->val = v; 
	return n; 
}

node_t *build_tree(char **post_pp, char *in_p)
{
	char *left, *right; 
	char v = **post_pp; 
	node_t *n = alloc_node(v); 
	if (*post_pp==postorder)
		return n; 
	left=in_p; 
	for(right=in_p; *right!=v; right++); 
	*right++ = '\0'; 
	if (*right) {
		--(*post_pp); 
		n->right = build_tree(post_pp, right); 
	}
	if (*left) {
		--(*post_pp); 
		n->left = build_tree(post_pp, left); 
	}
	return n; 
}

void walk_preorder(node_t *n)
{
	printf("%c", n->val); 
	if (n->left)
		walk_preorder(n->left); 
	if (n->right)
		walk_preorder(n->right); 
}

void walk_preorder_dbg(int lvl, node_t *n)
{
	int i; 
	for(i=0; i<lvl; i++) printf(" "); 
	printf("val=%c\n", n->val); 
	if (n->left) {
		for(i=0; i<lvl; i++) printf(" "); 
		printf("left: "); 
		walk_preorder_dbg(lvl+1, n->left); 
	}
	if (n->right) {
		for(i=0; i<lvl; i++) printf(" "); 
		printf("right: "); 
		walk_preorder_dbg(lvl+1, n->right); 
	}
}

int main()
{
	node_t *n;
	char *p; 
	scanf("%s", inorder); 
	scanf("%s", postorder); 
	for(p=postorder; *p; p++); 
	p--; 
	n = build_tree(&p, inorder); 
	walk_preorder(n); 
	printf("\n"); 
	return 0; 
}


